package org.dromara.system.service.impl;

import org.dromara.system.service.SysSocialService;
import org.dromara.system.pojo.entity.SysSocialDO;
import org.dromara.system.pojo.bo.SysSocialBO;
import org.dromara.system.pojo.qo.SysSocialQO;
import org.dromara.system.pojo.vo.SysSocialVO;
import org.dromara.system.mapper.SysSocialMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 社会化关系表 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysSocialServiceImpl  implements SysSocialService {

    private final SysSocialMapper sysSocialMapper;

    @Override
    public boolean add(SysSocialBO sysSocialBO) {
        SysSocialDO sysSocialDO = BeanCopyUtils.copy(sysSocialBO, SysSocialDO.class);
        return sysSocialMapper.insert(sysSocialDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysSocialMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysSocialBO sysSocialBO) {
        SysSocialDO sysSocialDO = BeanCopyUtils.copy(sysSocialBO, SysSocialDO.class);
        return sysSocialMapper.update(sysSocialDO) > 0;
    }

    @Override
    public List<SysSocialVO> list(SysSocialQO sysSocialQO) {
        SysSocialDO sysSocialDO = BeanCopyUtils.copy(sysSocialQO, SysSocialDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysSocialDO);
        return sysSocialMapper.selectListByQueryAs(queryWrapper, SysSocialVO.class);
    }

    @Override
    public SysSocialVO getInfo(@PathVariable Long id) {
        SysSocialDO sysSocialDO = sysSocialMapper.selectOneById(id);
        if (sysSocialDO == null){
            return null;
        }
        return BeanCopyUtils.copy(sysSocialDO, SysSocialVO.class);
    }

    @Override
    public Page<SysSocialVO> page(SysSocialQO page) {
        return sysSocialMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysSocialVO.class);
    }

}

